<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="theme-toggle">
        <input type="checkbox" id="theme-toggle-checkbox" />
        <label for="theme-toggle-checkbox"></label>
    </div>

    <style>
        .theme-toggle {
            position: relative;
            width: 60px;
            height: 30px;
        }

        .theme-toggle input[type="checkbox"] {
            display: none;
        }

        .theme-toggle label {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #ccc;
            border-radius: 15px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .theme-toggle label:before {
            content: "";
            position: absolute;
            top: 2px;
            left: 2px;
            width: 26px;
            height: 26px;
            background-color: #fff;
            border-radius: 50%;
            transition: transform 0.3s ease;
        }

        .theme-toggle input:checked+label {
            background-color: #555;
        }

        .theme-toggle input:checked+label:before {
            transform: translateX(30px);
        }

        .theme-toggle label:active:before {
            transform: scale(0.8);
        }

        /* 白天主题样式 */
        body {
            background-color: #fff;
            color: #000;
        }

        /* 黑夜主题样式 */
        body.dark-mode {
            background-color: #000;
            color: #fff;
        }
    </style>

    <script>
        const themeToggle = document.getElementById("theme-toggle-checkbox");
        const body = document.body;

        themeToggle.addEventListener("change", function () {
            if (this.checked) {
                body.classList.add("dark-mode");
            } else {
                body.classList.remove("dark-mode");
            }
        });
    </script>
</body>

</html>